package ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * 游戏菜单界面
 * 页面美化:szy
 */
public class GameMenuJFrame extends JFrame implements MouseListener {
    //菜单表头
    JButton jButton=new JButton("hello，life");
    //新游戏
    JButton newGame = new JButton("新游戏");
    //继续游戏
    JButton continueGame = new JButton("继续游戏");
    //帮助
    JButton help = new JButton("帮助");
    //成就
    JButton achievement = new JButton("成就");//展示成就
    //退出
    JButton exit = new JButton("退出");
    //返回登录
    JButton goBackLogin = new JButton("返回登录");

    public GameMenuJFrame() {
        //初始化界面
        initJFrame();
        //在这个界面中添加内容
        initView();
        //添加图片
        initImage();
        //是否可见(写在最后)
        this.setVisible(true);
    }
    private void initImage() {
        //添加背景图片
        JLabel background = new JLabel(new ImageIcon("src/image/GameMenuJFrame/背景.png"));
        background.setBounds(0, 0, 603, 680);
        this.getContentPane().add(background);
    }
    /**
     * 负责人:Szy
     * 功能:添加新游戏,继续游戏,帮助,成就,退出,返回登录等按钮
     * 点击对应按纽跳转至对应页面,为按钮添加动作监听或者鼠标监听
     */
    private void initView() {
        jButton.setBounds(160,25,240,50);
        jButton.setBackground(new Color(253, 222, 122));
        this.getContentPane().add(jButton);
        newGame.setBounds(180,95,200,50);
        newGame.setBackground(new Color(253, 222, 122));
        newGame.addMouseListener(this);
        this.getContentPane().add(newGame);
        continueGame.setBounds(180,165,200,50);
        continueGame.setBackground(new Color(253, 222, 122));
        continueGame.addMouseListener(this);
        this.getContentPane().add(continueGame);
        help.setBounds(180,235,200,50);
        help.setBackground(new Color(253, 222, 122));
        help.addMouseListener(this);
        this.getContentPane().add(help);
        achievement.setBounds(180,305,200,50);
        achievement.setBackground(new Color(253, 222, 122));
        achievement.addMouseListener(this);
        this.getContentPane().add(achievement);
        exit.setBounds(180,375,200,50);
        exit.setBackground(new Color(253, 222, 122));
        exit.addMouseListener(this);
        this.getContentPane().add(exit);
        goBackLogin.setBounds(180,445,200,50);
        goBackLogin.setBackground(new Color(253, 222, 122));
        goBackLogin.addMouseListener(this);
        this.getContentPane().add(goBackLogin);
    }

    private void initJFrame() {
        //设置长宽(像素)
        this.setSize(603, 680);
        //设置界面的标题
        this.setTitle("人生重开模拟器 v1.0");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //取消默认的居中方式,只有取消了才会按照,x y轴的方式添加组件
        this.setLayout(null);
        //给整个界面添加键盘监听
        //this.addKeyListener(this);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if(e.getSource()==newGame){
            Utils.Music.playSound("src\\music\\02.wav");
            new SelectAttributesJFrame();
            this.dispose();
        }else if(e.getSource()==goBackLogin){
            Utils.Music.playSound("src\\music\\02.wav");
            new LoginJFrame();
            this.dispose();
        }else if(e.getSource()==exit){
            Utils.Music.playSound("src\\music\\02.wav");
            System.exit(0);
        } else if (e.getSource() == help) {
            Utils.Music.playSound("src\\music\\02.wav");
            new HelpJFrame();
            this.dispose();
        } else if (e.getSource() == achievement) {
            Utils.Music.playSound("src\\music\\02.wav");
            JDialog dialog = new JDialog();
            JLabel jLabel=new JLabel(new ImageIcon(this.getClass().getResource("/image/GameMenuJFrame/游戏总成就展示.png")));
            jLabel.setBounds(0, 0, 500, 550);
            dialog.getContentPane().add(jLabel);
            dialog.setSize(500,550);
            dialog.setAlwaysOnTop(true);
            dialog.setLocationRelativeTo(null);
            dialog.setModal(true);//弹框不关闭则无法操作下面的界面
            dialog.setVisible(true);
        }
        else {
            Utils.Music.playSound("src\\music\\02.wav");
            JOptionPane.showMessageDialog(GameMenuJFrame.this, "暂未开通此功能");
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
